package com.zyl.client;

import com.zyl.bean.Environment;
import com.zyl.log.Log;
import com.zyl.log.LogImpl;

import java.io.*;
import java.net.Socket;
import java.util.List;

/**
 * @version v1.0
 * @ProjectName: env_gather
 * @Package: com.zyl.client
 * @ClassName: ClientImpl
 * @Description TODO(客户端模块实现类)
 * @Author 翟玉龙
 * @Date 2024/10/21-10:11
 */
public class ClientImpl implements Client {
    // 日志模块的实现类对象
    private final Log log = LogImpl.getInstance();

    @Override
    public void send(List<Environment> data) throws IOException {
        Socket socket = new Socket("localhost", 8088);
        // 输出环境对象集合数据
        OutputStream out = socket.getOutputStream();
        // 需要创建对象输出流
        // 使用BufferedOutputStream包装，提升传输效率
        ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(out));
        // 写出数据
        oos.writeObject(data);
        // 刷新数据
        oos.flush();
        // 关闭资源
        oos.close();
        socket.close();
        log.info("本次传输的数据条数为：" + data.size());
    }
}
